package com.woniuxy.rbac.mapper;

import com.woniuxy.rbac.entity.Perm;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermMapper {
    /**
     * 根据角色id查询权限列表
     *
     * @param roleId 角色id
     * @return 权限列表
     */
    @Select({"select p.* from rbac_perm p,rbac_role_perm rp ",
            " where p.id=rp.perm_id and rp.role_id=#{roleId}"})
    List<Perm> getByRoleId(int roleId);

    @Select("select * from v_perm where user_id=#{userId} and type='a'")
    List<Perm> getPermByUserId(int userId);

    @Select("select * from v_perm where user_id=#{userId} and type='m'")
    List<Perm> getMenuByUserId(int userId);

    @Select("select * from rbac_perm where link=#{link} and type='a' ")
    Perm getByLink(String link);

    @Select("select * from rbac_perm where type='a' and status='y'")
    List<Perm> getAllPerms();

    @Select("select * from rbac_perm where type='m' and status='y'")
    List<Perm> getAllMenus();

    @Select("select * from rbac_perm where status='y'")
    List<Perm> getAll();

}
